package com.ruoyi.framework.message;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

public class Producer {



    public static void sendMessage(String content) throws Exception {

// Initialize a producer and set the Producer group name

        DefaultMQProducer producer = new DefaultMQProducer("B23015140"); //（1）

// Set the address of NameServer

        producer.setNamesrvAddr("192.168.233.66:9876"); //（2）

// Start Producer

        producer.start();

// Create a message and set the topic, tag, body and so on. The tag can

//        be understood as a label to categorize the message, and RocketMQ can filter the tag on the consumer side.

                Message msg = new Message("B23015140" /* Topic */,

                "TagA" /* Tag */,

                (content).getBytes(RemotingHelper.DEFAULT_CHARSET) /* Message body */

        ); //（3）

// Use the producer to send and wait for the result of sending synchronously

        SendResult sendResult = producer.send(msg); //（4）

        System.out.printf("%s%n", sendResult);

// Close the producer once it is no longer in use

//        producer.shutdown();

    }

}